home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / as.sun3 / write.c < prev    next >
C/C++ Source or Header  |  1991-10-18  |  37KB  |  1,200 lines

  1. /* write.c - emit .o file - Copyright(C)1986 Free Software Foundation, Inc.
  2.    Copyright (C) 1986,1987 Free Software Foundation, Inc.
  3.  
  4. This file is part of GAS, the GNU Assembler.
  5.  
  6. GAS is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. GAS is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GAS; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. /* 
  21.  
  22.    Umm, with real good luck, this thing should be set up to do byteordering
  23.    correctly, but I may have managed to miss a place or two.  Treat a.out
  24.    very carefully until you're SURE that it works. . .
  25.  
  26.    In order to cross-assemble the target machine must have an a.out header
  27.    similar to the one in a.out.h on THIS machine.  Byteorder doesn't matter;
  28.    we take special care of it, but the numbers must be the same SIZE (# of
  29.    bytes) and in the same PLACE.  If this is not true, you will have some
  30.    trouble.
  31.  */
  32.  
  33. #include "as.h"
  34. #include "md.h"
  35. #include "subsegs.h"
  36. #include "obstack.h"
  37. #include "struc-symbol.h"
  38. #include "write.h"
  39. #include "symbols.h"
  40.  
  41. #ifdef SPARC
  42. #include "sparc.h"
  43. #endif
  44.  
  45. void    append();
  46.  
  47. #ifdef hpux
  48. #define EXEC_MACHINE_TYPE HP9000S200_ID
  49. #endif
  50.  
  51. /*
  52.  * In: length of relocation (or of address) in chars: 1, 2 or 4.
  53.  * Out: GNU LD relocation length code: 0, 1, or 2.
  54.  */
  55.  
  56. static unsigned char
  57.  
  58. nbytes_r_length [] = {
  59.   42, 0, 1, 42, 2
  60.   };
  61.  
  62.  
  63. static struct frag *    text_frag_root;
  64. static struct frag *    data_frag_root;
  65.  
  66. static struct frag *    text_last_frag;    /* Last frag in segment. */
  67. static struct frag *    data_last_frag;    /* Last frag in segment. */
  68.  
  69. static struct exec    the_exec;
  70.  
  71. static long int string_byte_count;
  72.  
  73. static char *        the_object_file;
  74.  
  75. #ifndef SPARC
  76. static
  77. #endif
  78. char *        next_object_file_charP;    /* Tracks object file bytes. */
  79.  
  80. static long int        size_of_the_object_file; /* # bytes in object file. */
  81.  
  82. /* static long int        length; JF unused */    /* String length, including trailing '\0'. */
  83.  
  84. static void    relax_segment();
  85. void        emit_segment();
  86. static relax_addressT    relax_align();
  87. static long int    fixup_segment();
  88. #ifndef SPARC
  89. static void        emit_relocations();
  90. #endif
  91. /*
  92.  *            fix_new()
  93.  *
  94.  * Create a fixS in obstack 'notes'.
  95.  */
  96. void
  97. #ifdef SPARC
  98. fix_new (frag, where, size, add_symbol, sub_symbol, offset, pcrel, r_type)
  99. #else
  100. fix_new (frag, where, size, add_symbol, sub_symbol, offset, pcrel)
  101. #endif
  102.      fragS *    frag;        /* Which frag? */
  103.      int    where;        /* Where in that frag? */
  104.      short int    size;        /* 1, 2  or 4 usually. */
  105.      symbolS *    add_symbol;    /* X_add_symbol. */
  106.      symbolS *    sub_symbol;    /* X_subtract_symbol. */
  107.      long int    offset;        /* X_add_number. */
  108.      int    pcrel;        /* TRUE if PC-relative relocation. */
  109. #ifdef SPARC
  110.     int        r_type;
  111. #endif
  112. {
  113.   register fixS *    fixP;
  114.  
  115.   fixP = (fixS *)obstack_alloc(¬es,sizeof(fixS));
  116.  
  117.   fixP -> fx_frag    = frag;
  118.   fixP -> fx_where    = where;
  119.   fixP -> fx_size    = size;
  120.   fixP -> fx_addsy    = add_symbol;
  121.   fixP -> fx_subsy    = sub_symbol;
  122.   fixP -> fx_offset    = offset;
  123.   fixP -> fx_pcrel    = pcrel;
  124.   fixP -> fx_next    = * seg_fix_rootP;
  125.  
  126.   /* JF these 'cuz of the NS32K stuff */
  127.   fixP -> fx_im_disp    = 0;
  128.   fixP -> fx_pcrel_adjust = 0;
  129.   fixP -> fx_bsr    = 0;
  130.   fixP ->fx_bit_fixP    = 0;
  131.  
  132. #ifdef SPARC
  133.   fixP->fx_r_type = r_type;
  134. #endif
  135.  
  136.   * seg_fix_rootP = fixP;
  137. }
  138.  
  139. void
  140. write_object_file()
  141. {
  142.   register struct frchain *    frchainP; /* Track along all frchains. */
  143.   register fragS *        fragP;    /* Track along all frags. */
  144.   register struct frchain *    next_frchainP;
  145.   register fragS * *        prev_fragPP;
  146.   register char *        name;
  147.   register symbolS *        symbolP;
  148.   register symbolS **        symbolPP;
  149.   /* register fixS *        fixP; JF unused */
  150.   unsigned
  151.       text_siz,
  152.     data_siz,
  153.     syms_siz,
  154.     tr_siz,
  155.     dr_siz;
  156.   void output_file_create();
  157.   void output_file_append();
  158.   void output_file_close();
  159.   void gdb_emit();
  160.   void gdb_end();
  161.   extern long omagic;        /* JF magic # to write out.  Is different for
  162.                    Suns and Vaxen and other boxes */
  163.  
  164. #ifdef    VMS
  165.   /*
  166.    *    Under VMS we try to be compatible with VAX-11 "C".  Thus, we
  167.    *    call a routine to check for the definition of the procedure
  168.    *    "_main", and if so -- fix it up so that it can be program
  169.    *    entry point.
  170.    */
  171.   VMS_Check_For_Main();
  172. #endif /* VMS */
  173.   /*
  174.    * After every sub-segment, we fake an ".align ...". This conforms to BSD4.2
  175.    * brane-damage. We then fake ".fill 0" because that is the kind of frag
  176.    * that requires least thought. ".align" frags like to have a following
  177.    * frag since that makes calculating their intended length trivial.
  178.    */
  179. #define SUB_SEGMENT_ALIGN (2)
  180.   for ( frchainP=frchain_root; frchainP; frchainP=frchainP->frch_next )
  181.     {
  182. #ifdef    VMS
  183.       /*
  184.        *    Under VAX/VMS, the linker (and PSECT specifications)
  185.        *    take care of correctly aligning the segments.
  186.        *    Doing the alignment here (on initialized data) can
  187.        *    mess up the calculation of global data PSECT sizes.
  188.        */
  189. #undef    SUB_SEGMENT_ALIGN
  190. #define    SUB_SEGMENT_ALIGN ((frchainP->frch_seg != SEG_DATA) ? 2 : 0)
  191. #endif    /* VMS */
  192.       subseg_new (frchainP -> frch_seg, frchainP -> frch_subseg);
  193.       frag_align (SUB_SEGMENT_ALIGN, 0);
  194.                 /* frag_align will have left a new frag. */
  195.                 /* Use this last frag for an empty ".fill". */
  196.       /*
  197.        * For this segment ...
  198.        * Create a last frag. Do not leave a "being filled in frag".
  199.        */
  200.       frag_wane (frag_now);
  201.       frag_now -> fr_fix    = 0;
  202.       know( frag_now -> fr_next == NULL );
  203.       /* know( frags . obstack_c_base == frags . obstack_c_next_free ); */
  204.       /* Above shows we haven't left a half-completed object on obstack. */
  205.     }
  206.  
  207.   /*
  208.    * From now on, we don't care about sub-segments.
  209.    * Build one frag chain for each segment. Linked thru fr_next.
  210.    * We know that there is at least 1 text frchain & at least 1 data frchain.
  211.    */
  212.   prev_fragPP = &text_frag_root;
  213.   for ( frchainP=frchain_root; frchainP; frchainP=next_frchainP )
  214.     {
  215.       know( frchainP -> frch_root );
  216.       * prev_fragPP = frchainP -> frch_root;
  217.       prev_fragPP = & frchainP -> frch_last -> fr_next;
  218.       if (   ((next_frchainP = frchainP->frch_next) == NULL)
  219.       || next_frchainP == data0_frchainP)
  220.     {
  221.       prev_fragPP = & data_frag_root;
  222.       if ( next_frchainP )
  223.         {
  224.           text_last_frag = frchainP -> frch_last;
  225.         }
  226.       else
  227.         {
  228.           data_last_frag = frchainP -> frch_last;
  229.         }
  230.     }
  231.     }                /* for(each struct frchain) */
  232.  
  233.   /*
  234.    * We have two segments. If user gave -R flag, then we must put the
  235.    * data frags into the text segment. Do this before relaxing so
  236.    * we know to take advantage of -R and make shorter addresses.
  237.    */
  238.   if ( flagseen [ 'R' ] )
  239.     {
  240.       fixS *tmp;
  241.  
  242.       text_last_frag -> fr_next = data_frag_root;
  243.       text_last_frag = data_last_frag;
  244.       data_last_frag = NULL;
  245.       data_frag_root = NULL;
  246.       if(text_fix_root) {
  247.     for(tmp=text_fix_root;tmp->fx_next;tmp=tmp->fx_next)
  248.       ;
  249.     tmp->fx_next=data_fix_root;
  250.       } else
  251.         text_fix_root=data_fix_root;
  252.       data_fix_root=NULL;
  253.     }
  254.  
  255.   relax_segment (text_frag_root, SEG_TEXT);
  256.   relax_segment (data_frag_root, SEG_DATA);
  257.   /*
  258.    * Now the addresses of frags are correct within the segment.
  259.    */
  260.  
  261.   know(   text_last_frag -> fr_type   == rs_fill && text_last_frag -> fr_offset == 0 );
  262.   text_siz=text_last_frag->fr_address;
  263. #ifdef SPARC
  264.   text_siz= (text_siz+7)&(~7);
  265.   text_last_frag->fr_address=text_siz;
  266. #endif
  267.   md_number_to_chars((char *)&the_exec.a_text,text_siz, sizeof(the_exec.a_text));
  268.   /* the_exec . a_text = text_last_frag -> fr_address; */
  269.  
  270.   /*
  271.    * Join the 2 segments into 1 huge segment.
  272.    * To do this, re-compute every rn_address in the SEG_DATA frags.
  273.    * Then join the data frags after the text frags.
  274.    *
  275.    * Determine a_data [length of data segment].
  276.    */
  277.   if (data_frag_root)
  278.     {
  279.       register relax_addressT    slide;
  280.  
  281.       know(   text_last_frag -> fr_type   == rs_fill && text_last_frag -> fr_offset == 0 );
  282.       data_siz=data_last_frag->fr_address;
  283. #ifdef SPARC
  284.       data_siz += (8 - (data_siz % 8)) % 8;
  285.       data_last_frag->fr_address = data_siz;
  286. #endif
  287.       md_number_to_chars((char *)&the_exec.a_data,data_siz,sizeof(the_exec.a_data));
  288.       /* the_exec . a_data = data_last_frag -> fr_address; */
  289.       slide = text_siz; /* Address in file of the data segment. */
  290.       for (fragP = data_frag_root;
  291.        fragP;
  292.        fragP = fragP -> fr_next)
  293.     {
  294.       fragP -> fr_address += slide;
  295.     }
  296.       know( text_last_frag );
  297.       text_last_frag -> fr_next = data_frag_root;
  298.     }
  299.   else {
  300.       md_number_to_chars((char *)&the_exec.a_data,0,sizeof(the_exec.a_data));
  301.       data_siz = 0;
  302.   }
  303.  
  304.   bss_address_frag . fr_address = text_siz + data_siz;
  305. #ifdef SPARC
  306.   local_bss_counter=(local_bss_counter+7)&(~7);
  307. #endif
  308.   md_number_to_chars((char *)&the_exec.a_bss,local_bss_counter,sizeof(the_exec.a_bss));
  309.  
  310.           
  311.   /*
  312.    *
  313.    * Crawl the symbol chain.
  314.    *
  315.    * For each symbol whose value depends on a frag, take the address of
  316.    * that frag and subsume it into the value of the symbol.
  317.    * After this, there is just one way to lookup a symbol value.
  318.    * Values are left in their final state for object file emission.
  319.    * We adjust the values of 'L' local symbols, even if we do
  320.    * not intend to emit them to the object file, because their values
  321.    * are needed for fix-ups.
  322.    *
  323.    * Unless we saw a -L flag, remove all symbols that begin with 'L'
  324.    * from the symbol chain.
  325.    *
  326.    * Count the (length of the nlists of the) (remaining) symbols.
  327.    * Assign a symbol number to each symbol.
  328.    * Count the number of string-table chars we will emit.
  329.    *
  330.    */
  331.   know( zero_address_frag . fr_address == 0 );
  332.   string_byte_count = sizeof( string_byte_count );
  333.  
  334.   /* JF deal with forward references first. . . */
  335.   for(symbolP=symbol_rootP;symbolP;symbolP=symbolP->sy_next) {
  336.       if(symbolP->sy_forward) {
  337.         symbolP->sy_value+=symbolP->sy_forward->sy_value+symbolP->sy_forward->sy_frag->fr_address;
  338.         symbolP->sy_forward=0;
  339.     }
  340.   }
  341.   symbolPP = & symbol_rootP;    /* -> last symbol chain link. */
  342.   {
  343.     register long int        symbol_number;
  344.  
  345.     symbol_number = 0;
  346.     while (symbolP  = * symbolPP)
  347.       {
  348.     name = symbolP -> sy_name;
  349.     if(flagseen['R'] && (symbolP->sy_nlist.n_type&N_DATA)) {
  350.       symbolP->sy_nlist.n_type&= ~N_DATA;
  351.       symbolP->sy_nlist.n_type|= N_TEXT;
  352.     }
  353.     /* if(symbolP->sy_forward) {
  354.       symbolP->sy_value += symbolP->sy_forward->sy_value + symbolP->sy_forward->sy_frag->fr_address;
  355.     } */
  356.     
  357.     symbolP -> sy_value += symbolP -> sy_frag -> fr_address;
  358.         /* JF the 128 bit is a hack so stabs like
  359.            "LET_STMT:23. . ."  don't go away */
  360.     /* CPH: 128 bit hack is moby loser.  N_SO for file "Lower.c"
  361.        fell through the cracks.  I think that N_STAB should be
  362.        used instead of 128. */
  363.         /* JF the \001 bit is to make sure that local labels
  364.            ( 1: - 9: don't make it into the symtable either */
  365. #ifndef    VMS    /* Under VMS we need to keep local symbols */
  366.     if ( !name || (symbolP->sy_nlist.n_type&N_STAB)
  367.         || (name[0]!='\001' && (flagseen ['L'] || name [0] != 'L' )))
  368. #endif    /* not VMS */
  369.       {
  370.         symbolP -> sy_number = symbol_number ++;
  371. #ifndef    VMS
  372.         if (name)
  373.           {            /* Ordinary case. */
  374.         symbolP -> sy_name_offset = string_byte_count;
  375.         string_byte_count += strlen (symbolP  -> sy_name) + 1;
  376.           }
  377.         else            /* .Stabd case. */
  378. #endif    /* not VMS */
  379.         symbolP -> sy_name_offset = 0;
  380.         symbolPP = & (symbolP -> sy_next);
  381.       }
  382. #ifndef    VMS
  383.     else
  384.         * symbolPP = symbolP -> sy_next;
  385. #endif    /* not VMS */
  386.       }                /* for each symbol */
  387.  
  388.     syms_siz = sizeof( struct nlist) * symbol_number;
  389.     md_number_to_chars((char *)&the_exec.a_syms,syms_siz,sizeof(the_exec.a_syms));
  390.     /* the_exec . a_syms = sizeof( struct nlist) * symbol_number; */
  391.   }
  392.  
  393.   /*
  394.    * Addresses of frags now reflect addresses we use in the object file.
  395.    * Symbol values are correct.
  396.    * Scan the frags, converting any ".org"s and ".align"s to ".fill"s.
  397.    * Also converting any machine-dependent frags using md_convert_frag();
  398.    */
  399.   subseg_change( SEG_TEXT, 0);
  400.  
  401.   for (fragP = text_frag_root;  fragP;  fragP = fragP -> fr_next)
  402.     {
  403.       switch (fragP -> fr_type)
  404.     {
  405.     case rs_align:
  406.     case rs_org:
  407.       fragP -> fr_type = rs_fill;
  408.       know( fragP -> fr_var == 1 );
  409.       know( fragP -> fr_next );
  410.       fragP -> fr_offset
  411.         =     fragP -> fr_next -> fr_address
  412.           -   fragP -> fr_address
  413.         - fragP -> fr_fix;
  414.       break;
  415.  
  416.     case rs_fill:
  417.       break;
  418.  
  419.     case rs_machine_dependent:
  420.       md_convert_frag (fragP);
  421.       /*
  422.        * After md_convert_frag, we make the frag into a ".space 0".
  423.        * Md_convert_frag() should set up any fixSs and constants
  424.        * required.
  425.        */
  426.       frag_wane (fragP);
  427.       break;
  428.  
  429. #ifndef WORKING_DOT_WORD
  430.     case rs_broken_word:
  431.       {
  432.         struct broken_word *lie;
  433.         extern md_short_jump_size;
  434.         extern md_long_jump_size;
  435.  
  436.         if(fragP->fr_subtype) {
  437.           fragP->fr_fix+=md_short_jump_size;
  438.           for(lie=(struct broken_word *)(fragP->fr_symbol);lie && lie->dispfrag==fragP;lie=lie->next_broken_word)
  439.         if(lie->added==1)
  440.           fragP->fr_fix+=md_long_jump_size;
  441.         }
  442.         frag_wane(fragP);
  443.       }
  444.       break;
  445. #endif
  446.  
  447.     default:
  448.       BAD_CASE( fragP -> fr_type );
  449.       break;
  450.     }            /* switch (fr_type) */
  451.     }                /* for each frag. */
  452.  
  453. #ifndef WORKING_DOT_WORD
  454.     {
  455.       struct broken_word *lie;
  456.       struct broken_word **prevP;
  457.  
  458.       prevP= &broken_words;
  459.       for(lie=broken_words; lie; lie=lie->next_broken_word)
  460.     if(!lie->added) {
  461. #ifdef SPARC
  462.       fix_new(    lie->frag,  lie->word_goes_here - lie->frag->fr_literal,
  463.               2,  lie->add,
  464.             lie->sub,  lie->addnum,
  465.             0,  NO_RELOC);
  466. #endif
  467. #ifdef NS32K
  468.       fix_new_ns32k(lie->frag,
  469.               lie->word_goes_here - lie->frag->fr_literal,
  470.             2,
  471.             lie->add,
  472.             lie->sub,
  473.             lie->addnum,
  474.             0, 2, 0, 0);
  475. #endif
  476. #if !defined(SPARC) && !defined(NS32K)
  477.       fix_new(    lie->frag,  lie->word_goes_here - lie->frag->fr_literal,
  478.               2,  lie->add,
  479.             lie->sub,  lie->addnum,
  480.             0);
  481. #endif
  482.       /* md_number_to_chars(lie->word_goes_here,
  483.                    lie->add->sy_value
  484.                    + lie->addnum
  485.                    - (lie->sub->sy_value),
  486.                  2); */
  487.       *prevP=lie->next_broken_word;
  488.     } else
  489.       prevP= &(lie->next_broken_word);
  490.  
  491.       for(lie=broken_words;lie;) {
  492.     struct broken_word *untruth;
  493.     char    *table_ptr;
  494.     long    table_addr;
  495.     long    from_addr,
  496.         to_addr;
  497.     int    n,
  498.         m;
  499.  
  500.     extern    md_short_jump_size;
  501.     extern    md_long_jump_size;
  502.     void    md_create_short_jump();
  503.     void    md_create_long_jump();
  504.  
  505.  
  506.  
  507.     fragP=lie->dispfrag;
  508.  
  509.     /* Find out how many broken_words go here */
  510.     n=0;
  511.     for(untruth=lie;untruth && untruth->dispfrag==fragP;untruth=untruth->next_broken_word)
  512.       if(untruth->added==1)
  513.         n++;
  514.  
  515.     table_ptr=lie->dispfrag->fr_opcode;
  516.     table_addr=lie->dispfrag->fr_address+(table_ptr - lie->dispfrag->fr_literal);
  517.     /* Create the jump around the long jumps */
  518.     /* This is a short jump from table_ptr+0 to table_ptr+n*long_jump_size */
  519.     from_addr=table_addr;
  520.     to_addr = table_addr + md_short_jump_size + n * md_long_jump_size;
  521.     md_create_short_jump(table_ptr,from_addr,to_addr,lie->dispfrag,lie->add);
  522.     table_ptr+=md_short_jump_size;
  523.     table_addr+=md_short_jump_size;
  524.  
  525.     for(m=0;lie && lie->dispfrag==fragP;m++,lie=lie->next_broken_word) {
  526.       if(lie->added==2)
  527.         continue;
  528.       /* Patch the jump table */
  529.       /* This is the offset from ??? to table_ptr+0 */
  530.       to_addr =   table_addr
  531.                 - (lie->sub->sy_value);
  532.       md_number_to_chars(lie->word_goes_here,to_addr,2);
  533.       for(untruth=lie->next_broken_word;untruth && untruth->dispfrag==fragP;untruth=untruth->next_broken_word) {
  534.         if(untruth->use_jump==lie)
  535.           md_number_to_chars(untruth->word_goes_here,to_addr,2);
  536.       }
  537.  
  538.       /* Install the long jump */
  539.       /* this is a long jump from table_ptr+0 to the final target */
  540.       from_addr=table_addr;
  541.       to_addr=lie->add->sy_value+lie->addnum;
  542.       md_create_long_jump(table_ptr,from_addr,to_addr,lie->dispfrag,lie->add);
  543.       table_ptr+=md_long_jump_size;
  544.       table_addr+=md_long_jump_size;
  545.     }
  546.       }
  547.     }
  548. #endif
  549. #ifndef    VMS
  550.   /*
  551.    * Scan every FixS performing fixups. We had to wait until now to do
  552.    * this because md_convert_frag() may have made some fixSs.
  553.    */
  554.   /* the_exec . a_trsize
  555.     = sizeof(struct relocation_info) * fixup_segment (text_fix_root, N_TEXT);
  556.   the_exec . a_drsize
  557.     = sizeof(struct relocation_info) * fixup_segment (data_fix_root, N_DATA); */
  558.  
  559.   tr_siz=sizeof(struct relocation_info) * fixup_segment (text_fix_root, N_TEXT);
  560.   md_number_to_chars((char *)&the_exec.a_trsize, tr_siz ,sizeof(the_exec.a_trsize));
  561.   dr_siz=sizeof(struct relocation_info) * fixup_segment (data_fix_root, N_DATA);
  562.   md_number_to_chars((char *)&the_exec.a_drsize, dr_siz, sizeof(the_exec.a_drsize));
  563. #ifdef EXEC_MACHINE_TYPE
  564.   md_number_to_chars((char *)&the_exec.a_machtype, EXEC_MACHINE_TYPE, sizeof(the_exec.a_machtype));
  565. #endif
  566.  
  567.   md_number_to_chars((char *)&the_exec.a_magic,omagic,sizeof(the_exec.a_magic));
  568.   md_number_to_chars((char *)&the_exec.a_entry,0,sizeof(the_exec.a_entry));
  569.   /* the_exec . a_entry = 0; */
  570.  
  571.   size_of_the_object_file =
  572.     sizeof( the_exec ) +
  573.       text_siz +
  574.         data_siz +
  575.       syms_siz +
  576.         tr_siz +
  577.           dr_siz +
  578.         string_byte_count;
  579.     
  580.   next_object_file_charP
  581.     = the_object_file
  582.       = xmalloc ( size_of_the_object_file );
  583.  
  584.   output_file_create (out_file_name);
  585.  
  586.   append (& next_object_file_charP, (char *)(&the_exec), (unsigned long)sizeof(the_exec));
  587.  
  588.   /*
  589.    * Emit code.
  590.    */
  591.   for (fragP = text_frag_root;  fragP;  fragP = fragP -> fr_next)
  592.     {
  593.       register long int        count;
  594.       register char *        fill_literal;
  595.       register long int        fill_size;
  596.  
  597.       know( fragP -> fr_type == rs_fill );
  598.       append (& next_object_file_charP, fragP -> fr_literal, (unsigned long)fragP -> fr_fix);
  599.       fill_literal= fragP -> fr_literal + fragP -> fr_fix;
  600.       fill_size   = fragP -> fr_var;
  601.       know( fragP -> fr_offset >= 0 );
  602.       for (count = fragP -> fr_offset;  count;  count --)
  603.       append (& next_object_file_charP, fill_literal, (unsigned long)fill_size);
  604.     }                /* for each code frag. */
  605.  
  606.   /*
  607.    * Emit relocations.
  608.    */
  609.   emit_relocations (text_fix_root, (relax_addressT)0);
  610.   emit_relocations (data_fix_root, text_last_frag -> fr_address);
  611.   /*
  612.    * Emit all symbols left in the symbol chain.
  613.    * Any symbol still undefined is made N_EXT.
  614.    */
  615.   for (   symbolP = symbol_rootP;   symbolP;   symbolP = symbolP -> sy_next   )
  616.     {
  617.       register char *    temp;
  618.  
  619.       temp = symbolP -> sy_nlist . n_un . n_name;
  620.       /* JF fix the numbers up. Call by value RULES! */
  621.       md_number_to_chars((char *)&(symbolP -> sy_nlist  . n_un . n_strx ),symbolP -> sy_name_offset,sizeof(symbolP -> sy_nlist  . n_un . n_strx ));
  622.       md_number_to_chars((char *)&(symbolP->sy_nlist.n_desc),symbolP->sy_nlist.n_desc,sizeof(symbolP -> sy_nlist  . n_desc));
  623.       md_number_to_chars((char *)&(symbolP->sy_nlist.n_value),symbolP->sy_nlist.n_value,sizeof(symbolP->sy_nlist.n_value));
  624.       /* symbolP -> sy_nlist  . n_un . n_strx = symbolP -> sy_name_offset; JF replaced by md above */
  625.       if (symbolP -> sy_type == N_UNDF)
  626.       symbolP -> sy_type |= N_EXT; /* Any undefined symbols become N_EXT. */
  627.       append (& next_object_file_charP, (char *)(& symbolP -> sy_nlist),
  628.           (unsigned long)sizeof(struct nlist));
  629.       symbolP -> sy_nlist . n_un . n_name = temp;
  630.     }                /* for each symbol */
  631.  
  632.   /*
  633.    * next_object_file_charP -> slot for next object byte.
  634.    * Emit strings.
  635.    * Find strings by crawling along symbol table chain.
  636.    */
  637. /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK */
  638.   md_number_to_chars((char *)&string_byte_count, string_byte_count, sizeof(string_byte_count));
  639.  
  640.   append (& next_object_file_charP, (char *)&string_byte_count, (unsigned long)sizeof(string_byte_count));
  641.   for (   symbolP = symbol_rootP;   symbolP;   symbolP = symbolP -> sy_next   )
  642.     {
  643.       if (symbolP -> sy_name)
  644.     {            /* Ordinary case: not .stabd. */
  645.       append (& next_object_file_charP, symbolP -> sy_name,
  646.           (unsigned long)(strlen (symbolP -> sy_name) + 1));
  647.     }
  648.     }                /* for each symbol */
  649.  
  650.   know( next_object_file_charP == the_object_file + size_of_the_object_file );
  651.  
  652.   output_file_append (the_object_file, size_of_the_object_file, out_file_name);
  653.  
  654.   if (flagseen['G'])        /* GDB symbol file to be appended? */
  655.     {
  656.       gdb_emit (out_file_name);
  657.       gdb_end ();
  658.     }
  659.  
  660.   output_file_close (out_file_name);
  661. #else    /* VMS */
  662.   /*
  663.    *    Now do the VMS-dependent part of writing the object file
  664.    */
  665.   VMS_write_object_file(text_siz, data_siz, text_frag_root, data_frag_root);
  666. #endif    /* VMS */
  667. }                /* write_object_file() */
  668.  
  669. /*
  670.  *            relax_segment()
  671.  *
  672.  * Now we have a segment, not a crowd of sub-segments, we can make fr_address
  673.  * values.
  674.  *
  675.  * Relax the frags.
  676.  *
  677.  * After this, all frags in this segment have addresses that are correct
  678.  * within the segment. Since segments live in different file addresses,
  679.  * these frag addresses may not be the same as final object-file addresses.
  680.  */
  681. #ifndef    VMS
  682. static
  683. #endif    /* not VMS */
  684. void
  685. relax_segment (segment_frag_root, segment_type)
  686.      struct frag *    segment_frag_root;
  687.      segT        segment_type; /* N_DATA or N_TEXT */
  688. {
  689.   register struct frag *    fragP;
  690.   register relax_addressT    address;
  691.   /* register relax_addressT    old_address; JF unused */
  692.   /* register relax_addressT    new_address; JF unused */
  693.  
  694.   know( segment_type == SEG_DATA || segment_type == SEG_TEXT );
  695.  
  696.   /* In case md_estimate_size_before_relax() wants to make fixSs. */
  697.   subseg_change (segment_type, 0);
  698.  
  699.   /*
  700.    * For each frag in segment: count and store  (a 1st guess of) fr_address.
  701.    */
  702.   address = 0;
  703.   for ( fragP = segment_frag_root;   fragP;   fragP = fragP -> fr_next )
  704.     {
  705.       fragP -> fr_address = address;
  706.       address += fragP -> fr_fix;
  707.       switch (fragP -> fr_type)
  708.     {
  709.     case rs_fill:
  710.       address += fragP -> fr_offset * fragP -> fr_var;
  711.       break;
  712.  
  713.     case rs_align:
  714.       address += relax_align (address, fragP -> fr_offset);
  715.       break;
  716.  
  717.     case rs_org:
  718.       /*
  719.        * Assume .org is nugatory. It will grow with 1st relax.
  720.        */
  721.       break;
  722.  
  723.     case rs_machine_dependent:
  724.       address += md_estimate_size_before_relax
  725.         (fragP, seg_N_TYPE [(int) segment_type]);
  726.       break;
  727.  
  728. #ifndef WORKING_DOT_WORD
  729.         /* Broken words don't concern us yet */
  730.     case rs_broken_word:
  731.         break;
  732. #endif
  733.  
  734.     default:
  735.       BAD_CASE( fragP -> fr_type );
  736.       break;
  737.     }            /* switch(fr_type) */
  738.     }                /* for each frag in the segment */
  739.  
  740.   /*
  741.    * Do relax().
  742.    */
  743.   {
  744.     register long int    stretch; /* May be any size, 0 or negative. */
  745.                 /* Cumulative number of addresses we have */
  746.                 /* relaxed this pass. */
  747.                 /* We may have relaxed more than one address. */
  748.     register long int stretched;  /* Have we stretched on this pass? */
  749.                   /* This is 'cuz stretch may be zero, when,
  750.                      in fact some piece of code grew, and
  751.                      another shrank.  If a branch instruction
  752.                      doesn't fit anymore, we could be scrod */
  753.  
  754.     do
  755.       {
  756.     stretch = stretched = 0;
  757.     for (fragP = segment_frag_root;  fragP;  fragP = fragP -> fr_next)
  758.       {
  759.         register long int    growth;
  760.         register long int    was_address;
  761.         /* register long int    var; */
  762.         register long int    offset;
  763.         register symbolS *    symbolP;
  764.         register long int    target;
  765.         register long int    after;
  766.         register long int    aim;
  767.  
  768.         was_address = fragP -> fr_address;
  769.         address = fragP -> fr_address += stretch;
  770.         symbolP = fragP -> fr_symbol;
  771.         offset = fragP -> fr_offset;
  772.         /* var = fragP -> fr_var; */
  773.         switch (fragP -> fr_type)
  774.           {
  775.           case rs_fill:    /* .fill never relaxes. */
  776.         growth = 0;
  777.         break;
  778.  
  779. #ifndef WORKING_DOT_WORD
  780.         /* JF:  This is RMS's idea.  I do *NOT* want to be blamed
  781.            for it I do not want to write it.  I do not want to have
  782.            anything to do with it.  This is not the proper way to
  783.            implement this misfeature. */
  784.           case rs_broken_word:
  785.             {
  786.         struct broken_word *lie;
  787.         struct broken_word *untruth;
  788.         extern int md_short_jump_size;
  789.         extern int md_long_jump_size;
  790.  
  791.             /* Yes this is ugly (storing the broken_word pointer
  792.                in the symbol slot).  Still, this whole chunk of
  793.                code is ugly, and I don't feel like doing anything
  794.                about it.  Think of it as stubbornness in action */
  795.         growth=0;
  796.             for(lie=(struct broken_word *)(fragP->fr_symbol);
  797.             lie && lie->dispfrag==fragP;
  798.             lie=lie->next_broken_word) {
  799.  
  800.             if(lie->added)
  801.                 continue;
  802.             offset=  lie->add->sy_frag->fr_address+lie->add->sy_value + lie->addnum -
  803.                 (lie->sub->sy_frag->fr_address+lie->sub->sy_value);
  804.             if(offset<=-32768 || offset>=32767) {
  805.                 if(flagseen['k'])
  806.                     as_warn(".word %s-%s+%ld didn't fit",lie->add->sy_name,lie->sub->sy_name,lie->addnum);
  807.                 lie->added=1;
  808.                 if(fragP->fr_subtype==0) {
  809.                     fragP->fr_subtype++;
  810.                     growth+=md_short_jump_size;
  811.                 }
  812.                 for(untruth=lie->next_broken_word;untruth && untruth->dispfrag==lie->dispfrag;untruth=untruth->next_broken_word)
  813.                     if(untruth->add->sy_frag==lie->add->sy_frag && untruth->add->sy_value==lie->add->sy_value) {
  814.                         untruth->added=2;
  815.                         untruth->use_jump=lie;
  816.                     }
  817.                 growth+=md_long_jump_size;
  818.             }
  819.             }
  820.         }
  821.         break;
  822. #endif
  823.           case rs_align:
  824.         growth = relax_align ((relax_addressT)(address + fragP -> fr_fix), offset)
  825.           - relax_align ((relax_addressT)(was_address +  fragP -> fr_fix), offset);
  826.         break;
  827.  
  828.           case rs_org:
  829.         target = offset;
  830.         if (symbolP)
  831.           {
  832.             know(   ((symbolP -> sy_type & N_TYPE) == N_ABS) || ((symbolP -> sy_type & N_TYPE) == N_DATA) || ((symbolP -> sy_type & N_TYPE) == N_TEXT));
  833.             know( symbolP -> sy_frag );
  834.             know( (symbolP->sy_type&N_TYPE)!=N_ABS || symbolP->sy_frag==&zero_address_frag );
  835.             target +=
  836.               symbolP -> sy_value
  837.             + symbolP -> sy_frag -> fr_address;
  838.           }
  839.         know( fragP -> fr_next );
  840.         after = fragP -> fr_next -> fr_address;
  841.         growth - ((target - after ) > 0) ? (target - after) : 0;
  842.                 /* Growth may be -ve, but variable part */
  843.                 /* of frag cannot have < 0 chars. */
  844.                 /* That is, we can't .org backwards. */
  845.  
  846.         growth -= stretch;    /* This is an absolute growth factor */
  847.         break;
  848.  
  849.           case rs_machine_dependent:
  850.         {
  851.           register relax_typeS *    this_type;
  852.           register relax_typeS *    start_type;
  853.           register relax_substateT    next_state;
  854.           register relax_substateT    this_state;
  855.  
  856.           start_type = this_type
  857.             = md_relax_table + (this_state = fragP -> fr_subtype);
  858.         target = offset;
  859.         if (symbolP)
  860.           {
  861.  know(   ((symbolP -> sy_type & N_TYPE) == N_ABS) || ((symbolP -> sy_type &
  862.  N_TYPE) == N_DATA) || ((symbolP -> sy_type & N_TYPE) == N_TEXT));
  863.             know( symbolP -> sy_frag );
  864.             know( (symbolP->sy_type&N_TYPE)!=N_ABS || symbolP->sy_frag==&zero_address_frag );
  865.             target +=
  866.               symbolP -> sy_value
  867.             + symbolP -> sy_frag -> fr_address;
  868.  
  869.             /* If frag has yet to be reached on this pass,
  870.                assume it will move by STRETCH just as we did.
  871.                If this is not so, it will be because some frag
  872.                between grows, and that will force another pass.  */
  873.  
  874.                    /* JF was just address */
  875.                 /* JF also added isdnrange hack */
  876.                 /* There's gotta be a better/faster/etc way
  877.                    to do this. . . */
  878.             if (symbolP->sy_frag->fr_address > was_address && isdnrange(fragP,symbolP->sy_frag))
  879.               target += stretch;
  880.  
  881.           }
  882.           aim = target - address - fragP -> fr_fix;
  883.           if (aim < 0)
  884.             {
  885.               /* Look backwards. */
  886.               for (next_state = this_type -> rlx_more;  next_state;  )
  887.             {
  888.               if (aim >= this_type -> rlx_backward)
  889.                   next_state = 0;
  890.               else
  891.                 {    /* Grow to next state. */
  892.                   this_type = md_relax_table + (this_state = next_state);
  893.                   next_state = this_type -> rlx_more;
  894.                 }
  895.             }
  896.             }
  897.           else
  898.             {
  899. #ifdef DONTDEF
  900. /* JF these next few lines of code are for the mc68020 which can't handle short
  901.    offsets of zero in branch instructions.  What a kludge! */
  902.  if(aim==0 && this_state==(1<<2+0)) {    /* FOO hard encoded from m.c */
  903.     aim=this_type->rlx_forward+1;    /* Force relaxation into word mode */
  904.  }
  905. #endif
  906. /* JF end of 68020 code */
  907.               /* Look forwards. */
  908.               for (next_state = this_type -> rlx_more;  next_state;  )
  909.             {
  910.               if (aim <= this_type -> rlx_forward)
  911.                   next_state = 0;
  912.               else
  913.                 {    /* Grow to next state. */
  914.                   this_type = md_relax_table + (this_state = next_state);
  915.                   next_state = this_type -> rlx_more;
  916.                 }
  917.             }
  918.             }
  919.           if (growth = this_type -> rlx_length - start_type -> rlx_length)
  920.               fragP -> fr_subtype = this_state;
  921.         }
  922.         break;
  923.  
  924.           default:
  925.         BAD_CASE( fragP -> fr_type );
  926.         break;
  927.           }
  928.         if(growth) {
  929.           stretch += growth;
  930.           stretched++;
  931.         }
  932.       }            /* For each frag in the segment. */
  933.       } while (stretched);    /* Until nothing further to relax. */
  934.   }
  935.  
  936.   /*
  937.    * We now have valid fr_address'es for each frag.
  938.    */
  939.  
  940.   /*
  941.    * All fr_address's are correct, relative to their own segment.
  942.    * We have made all the fixS we will ever make.
  943.    */
  944. }                /* relax_segment() */
  945.  
  946. /*
  947.  * Relax_align. Advance location counter to next address that has 'alignment'
  948.  * lowest order bits all 0s.
  949.  */
  950.  
  951. static relax_addressT        /* How many addresses does the .align take? */
  952. relax_align (address, alignment)
  953.      register relax_addressT    address; /* Address now. */
  954.      register long int        alignment; /* Alignment (binary). */
  955. {
  956.   relax_addressT    mask;
  957.   relax_addressT    new_address;
  958.  
  959.   mask = ~ ( (~0) << alignment );
  960.   new_address = (address + mask) & (~ mask);
  961.   return (new_address - address);
  962. }
  963.  
  964. /*
  965.  *            fixup_segment()
  966.  */
  967. static long int
  968. fixup_segment (fixP, this_segment_type)
  969.      register fixS *    fixP;
  970.      int        this_segment_type; /* N_TYPE bits for segment. */
  971. {
  972.   register long int        seg_reloc_count;
  973.         /* JF these all used to be local to the for loop, but GDB doesn't seem to be able to deal with them there, so I moved them here for a bit. */
  974.       register symbolS *    add_symbolP;
  975.       register symbolS *    sub_symbolP;
  976.       register long int        add_number;
  977.       register int        size;
  978.       register char *        place;
  979.       register long int        where;
  980.       register char        pcrel;
  981.       register fragS *        fragP;
  982.       register int        add_symbol_N_TYPE;
  983.  
  984.  
  985.   seg_reloc_count = 0;
  986.   for ( ;  fixP;  fixP = fixP -> fx_next)
  987.     {
  988.       fragP       = fixP  -> fx_frag;
  989.       know( fragP );
  990.       where      = fixP  -> fx_where;
  991.       place       = fragP -> fr_literal + where;
  992.       size      = fixP  -> fx_size;
  993.       add_symbolP = fixP  -> fx_addsy;
  994.       sub_symbolP = fixP  -> fx_subsy;
  995.       add_number  = fixP  -> fx_offset;
  996.       pcrel      = fixP  -> fx_pcrel;
  997.       if(add_symbolP)
  998.     add_symbol_N_TYPE = add_symbolP -> sy_type & N_TYPE;
  999.       if (sub_symbolP)
  1000.     {
  1001.       if(!add_symbolP)    /* Its just -sym */
  1002.         {
  1003.           if(sub_symbolP->sy_type!=N_ABS)
  1004.             as_warn("Negative of non-absolute symbol %s", sub_symbolP->sy_name);
  1005.           add_number-=sub_symbolP->sy_value;
  1006.         }
  1007.       else if (   ((sub_symbolP -> sy_type ^ add_symbol_N_TYPE) & N_TYPE) == 0
  1008.           && (   add_symbol_N_TYPE == N_DATA
  1009.           || add_symbol_N_TYPE == N_TEXT
  1010.           || add_symbol_N_TYPE == N_BSS
  1011.           || add_symbol_N_TYPE == N_ABS))
  1012.         {
  1013.           /* Difference of 2 symbols from same segment. */
  1014.           /* Can't make difference of 2 undefineds: 'value' means */
  1015.           /* something different for N_UNDF. */
  1016.           add_number += add_symbolP -> sy_value - sub_symbolP -> sy_value;
  1017.           add_symbolP = NULL;
  1018.           fixP -> fx_addsy = NULL;
  1019.         }
  1020.       else
  1021.         {
  1022.           /* Different segments in subtraction. */
  1023.           know( sub_symbolP -> sy_type != (N_ABS | N_EXT))
  1024.         if (sub_symbolP -> sy_type == N_ABS)
  1025.             add_number -= sub_symbolP -> sy_value;
  1026.         else
  1027.           {
  1028.                as_warn("Can't emit reloc {- %s-seg symbol \"%s\"} @ file address %d.",
  1029.                     seg_name[(int)N_TYPE_seg[sub_symbolP->sy_type&N_TYPE]],
  1030.                     sub_symbolP -> sy_name, fragP -> fr_address + where);
  1031.           }
  1032.         }
  1033.     }
  1034.       if (add_symbolP)
  1035.     {
  1036.       if (add_symbol_N_TYPE == this_segment_type && pcrel)
  1037.         {
  1038.           /*
  1039.            * This fixup was made when the symbol's segment was
  1040.            * SEG_UNKNOWN, but it is now in the local segment.
  1041.            * So we know how to do the address without relocation.
  1042.            */
  1043.           add_number += add_symbolP -> sy_value;
  1044.           add_number -= size + where + fragP -> fr_address;
  1045.           pcrel = 0;    /* Lie. Don't want further pcrel processing. */
  1046.           fixP -> fx_addsy = NULL; /* No relocations please. */
  1047.           /*
  1048.            * It would be nice to check that the address does not overflow.
  1049.            * I didn't do this check because:
  1050.            * +  It is machine dependent in the general case (eg 32032)
  1051.            * +  Compiler output will never need this checking, so why
  1052.            *    slow down the usual case?
  1053.            */
  1054.         }
  1055.       else
  1056.         {
  1057.           switch (add_symbol_N_TYPE)
  1058.         {
  1059.         case N_ABS:
  1060.           add_number += add_symbolP -> sy_value;
  1061.           fixP -> fx_addsy = NULL;
  1062.           add_symbolP = NULL;
  1063.           break;
  1064.           
  1065.         case N_BSS:
  1066.         case N_DATA:
  1067.         case N_TEXT:
  1068.           seg_reloc_count ++;
  1069.           add_number += add_symbolP -> sy_value;
  1070.           break;
  1071.           
  1072.         case N_UNDF:
  1073.           seg_reloc_count ++;
  1074.           break;
  1075.           
  1076.         default:
  1077.           BAD_CASE( add_symbol_N_TYPE );
  1078.           break;
  1079.         }        /* switch on symbol seg */
  1080.         }            /* if not in local seg */
  1081.     }            /* if there was a + symbol */
  1082.       if (pcrel)
  1083.     {
  1084.       add_number -= size + where + fragP -> fr_address;
  1085.       if (add_symbolP == 0)
  1086.         {
  1087.           fixP -> fx_addsy = & abs_symbol;
  1088.           seg_reloc_count ++;
  1089.         }
  1090.     }
  1091.       /* OVE added fx_im_disp for ns32k and others */
  1092.       if (!fixP->fx_bit_fixP) {
  1093.     /* JF I hope this works . . . */
  1094.     if((size==1 && (add_number& ~0xFF)   && (add_number&~0xFF!=(-1&~0xFF))) ||
  1095.        (size==2 && (add_number& ~0xFFFF) && (add_number&~0xFFFF!=(-1&~0xFFFF))))
  1096.       as_warn("Fixup of %d too large for field width of %d",add_number, size);
  1097.  
  1098.     switch (fixP->fx_im_disp) {
  1099.     case 0:
  1100. #ifdef SPARC
  1101.       fixP->fx_addnumber = add_number;
  1102.       md_number_to_imm(place, add_number, size, fixP, this_segment_type);
  1103. #else
  1104.       md_number_to_imm (place, add_number, size);
  1105.       /* OVE: the immediates, like disps, have lsb at lowest address */
  1106. #endif
  1107.       break;
  1108.     case 1:
  1109.       md_number_to_disp (place,
  1110.                  fixP->fx_pcrel ? add_number+fixP->fx_pcrel_adjust:add_number,
  1111.                  size);
  1112.       break;
  1113.     case 2: /* fix requested for .long .word etc */
  1114.       md_number_to_chars (place, add_number, size);
  1115.       break;
  1116.     default:
  1117.       as_fatal("Internal error in write.c in fixup_segment");
  1118.     } /* OVE: maybe one ought to put _imm _disp _chars in one md-func */
  1119.       } else {
  1120.     md_number_to_field (place, add_number, fixP->fx_bit_fixP);
  1121.       }
  1122.     }                /* For each fixS in this segment. */
  1123.   return (seg_reloc_count);
  1124. }                /* fixup_segment() */
  1125.  
  1126.  
  1127. /* The sparc needs its own emit_relocations() */
  1128. #ifndef SPARC
  1129. /*
  1130.  *        emit_relocations()
  1131.  *
  1132.  * Crawl along a fixS chain. Emit the segment's relocations.
  1133.  */
  1134. static void
  1135. emit_relocations (fixP, segment_address_in_file)
  1136.      register fixS *    fixP;    /* Fixup chain for this segment. */
  1137.      relax_addressT    segment_address_in_file;
  1138. {
  1139.   struct relocation_info    ri;
  1140.   register symbolS *        symbolP;
  1141.  
  1142.     /* JF this is for paranoia */
  1143.   bzero((char *)&ri,sizeof(ri));
  1144.   for ( ;  fixP;  fixP = fixP -> fx_next)
  1145.     {
  1146.       if (symbolP = fixP -> fx_addsy)
  1147.     {
  1148.  
  1149. #if 0
  1150.         /* These two 'cuz of NS32K */
  1151.       ri . r_bsr        = fixP -> fx_bsr;
  1152.       ri . r_disp        = fixP -> fx_im_disp;
  1153. #endif
  1154.  
  1155.       ri . r_length        = nbytes_r_length [fixP -> fx_size];
  1156.       ri . r_pcrel        = fixP -> fx_pcrel;
  1157.       ri . r_address    = fixP -> fx_frag -> fr_address
  1158.         +   fixP -> fx_where
  1159.           - segment_address_in_file;
  1160.       if ((symbolP -> sy_type & N_TYPE) == N_UNDF)
  1161.         {
  1162.           ri . r_extern    = 1;
  1163.           ri . r_symbolnum    = symbolP -> sy_number;
  1164.         }
  1165.       else
  1166.         {
  1167.           ri . r_extern    = 0;
  1168.           ri . r_symbolnum    = symbolP -> sy_type & N_TYPE;
  1169.         }
  1170.  
  1171.       /* 
  1172.         The 68k machines assign bit-fields from higher bits to 
  1173.         lower bits ("left-to-right") within the int.  VAXen assign 
  1174.         bit-fields from lower bits to higher bits ("right-to-left").
  1175.         Both handle multi-byte numbers in their usual fashion
  1176.         (Big-endian and little-endian stuff).
  1177.         Thus we need a machine dependent routine to make
  1178.         sure the structure is written out correctly.  FUN!
  1179.        */
  1180.       md_ri_to_chars((char *) &ri, ri); 
  1181.       append (&next_object_file_charP, (char *)& ri, (unsigned long)sizeof(ri));
  1182.     }
  1183.     }
  1184.  
  1185. }
  1186. #endif
  1187.  
  1188. int
  1189. isdnrange(f1,f2)
  1190. struct frag *f1,*f2;
  1191. {
  1192.     while(f1) {
  1193.         if(f1->fr_next==f2)
  1194.             return 1;
  1195.         f1=f1->fr_next;
  1196.     }
  1197.     return 0;
  1198. }
  1199. /* End: as-write.c */
  1200.